package com.guoxin.part4.chapter17;

/**
 * ReadWriteLock interface define
 *
 * @author guoxin
 */
public interface ReadWriteLock {
    /**
     * create reader lock
     *
     * @return read Lock
     */
    Lock readLock();

    /**
     * create write lock
     *
     * @return Lock
     */
    Lock writeLock();

    /**
     * get how many threads writing for write
     *
     * @return writing for write threads count
     */
    int getWritingWriters();

    /**
     * get how many threads waiting for write
     *
     * @return current working thread count
     */
    int getWaitingWriters();

    /**
     * get how many threads writing for reader
     *
     * @return writing for reader threads count
     */
    int getReadingReaders();

    /**
     * factory method to create ReadWriteLock
     *
     * @return ReadWriteLock
     */
    static ReadWriteLock readWriteLock() {
        return new ReadWriteLockImpl();
    }

    /**
     * factory method to create ReadWriteLock
     *
     * @param preferWriter boolean
     * @return ReadWriteLock
     */
    static ReadWriteLock readWriteLock(boolean preferWriter) {
        return new ReadWriteLockImpl(preferWriter);
    }
}
